package com.whc.controller;

import com.whc.dto.OrderDto;
import com.whc.entity.Orders;
import com.whc.result.Result;
import com.whc.service.GoodsService;
import com.whc.service.OrdersService;
import com.whc.vo.GoodsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 韦红材
 * @ClassName OrdersController
 * @data 2024/12/27 20:47
 * @Version V1.0
 **/
@RestController
@Api(tags = "订单接口")
@RequestMapping("/client/order")
@Slf4j
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private GoodsService goodsService;

    @ApiOperation("添加订单(即购买功能)")
    @PostMapping("/addOrders")
    public Result addOrders(@RequestBody OrderDto orderDto){
        ordersService.addOrder(orderDto);
        return Result.success();
    }

    @ApiOperation("查询用户购买的商品")
    @GetMapping("/selectBoughtGoods/{userId}")
    public Result<List<GoodsVo>>  selectBoughtGoods(@PathVariable Long userId){
        List<GoodsVo> goodsVos = goodsService.selectBoughtGoods(userId);
        return Result.success(goodsVos);
    }

    @ApiOperation("查询用户卖出的商品")
    @GetMapping("/selectSoldGoods/{userId}")
    public Result<List<GoodsVo>>  selectSoldGoods(@PathVariable Long userId){
        List<GoodsVo> goodsVos = goodsService.selectSoldGoods(userId);
        return Result.success(goodsVos);
    }

}
